<?PHP
/****************************************/
/************* IdeaLAN LLC **************/
/* Test file to creat new functions and */
/* to test other scripts amd ideas.     */
/*                                      */
/****************************************/
/****************************************/
/* SCRIPT: test.php     VER: 0.0        */
/* AUTHOR: Lukasz Piekarski             */
/* E-mail: lukasz@idealan.net           */
/****************************************/


// QUERIES TO RETRIVE FROM DATABASE
$allso_query = "SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_status` = '0'"; 
$sototal_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1'"); 
$soopen_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_status` = '0'"); 
$sopaid_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_status` = '1'"); 
$sorefunded_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_status` = '2'"); 
$socanceled_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_status` = '3'"); 

$sopaidcheck_query = mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_paytype` = '0' AND `so_status` NOT LIKE '0'");
$sopaidcash_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_paytype` = '1' AND `so_status` NOT LIKE '0'");
$sopaidpp_query = 	mysql_query("SELECT * FROM `".$DBprefix."service_orders` WHERE  `so_id` NOT LIKE  '1' AND `so_paytype` = '3' AND `so_status` NOT LIKE '0'");

$customer_query = mysql_query("SELECT * FROM `".$DBprefix."customers` ORDER BY `cust_id` DESC"); 


// COUNT ENTRIES
$sototal_count = mysql_num_rows($sototal_query);			// COUNTS THE TOTAL OF SO's
$soopen_count = mysql_num_rows($soopen_query);			// COUNTS THE TOTAL OF OPEN SO's
$sopaid_count = mysql_num_rows($sopaid_query);			// COUNTS THE TOTAL OF PAID SO's
$sorefunded_count = mysql_num_rows($sorefunded_query);		// COUNTS THE TOTAL OF REFUNDED SO's
$socanceled_count = mysql_num_rows($socanceled_query);		// COUNTS THE TOTAL OF CANCELED SO's
$sopaidcheck_count = mysql_num_rows($sopaidcheck_query);	// COUNTS THE TOTAL OF SO's PAID WITH CHECKS
$sopaidcash_count = mysql_num_rows($sopaidcash_query);		// COUNTS THE TOTAL OF SO's PAID WITH CASH
$sopaidpp_count = mysql_num_rows($sopaidpp_query);		// COUNTS THE TOTAL OF SO's PAID WITH PAYPAL

$customer_count =  mysql_num_rows($customer_query);		// COUNTS THE TOTAL NUMBER OF CUSTOMERS

// HERE WE WILL GET THE NEWEST ADDED CUSTOMER AND WE WILL CHECK IF THE CUSTOMER MOD ID #
$check_module = "SELECT * FROM `".$DBprefix."modules` WHERE `mod_name` = 'Customers' AND `mod_location` = 'customers.php'";  
$execute_check_module = mysql_query($check_module); 

if ($custmod = mysql_fetch_array($execute_check_module)){
	$cust_modid = $custmod["mod_id"];

}


if ($cust = mysql_fetch_array($customer_query)){
	
	$cust_id = $cust["cust_id"];
	$cust_fname = $cust["cust_fname"];
	$cust_lname = $cust["cust_lname"];

}

// THIS PART WILL CALCULATE THE TOTAL FOR ALL THE INVOICES

$execute_get_allso = mysql_query($allso_query); 
while ($so = mysql_fetch_array($execute_get_allso)){
	
	$so_id = $so["so_id"];
	$so_tax = $so["so_tax"];
	
// WE NEED TO RESET THE VARIABLES TO 0

	$so_total = "";
	$item_subtotal = "";
	$item_discount = "";
	$item_total = "";
	$so_shTotal = "";
	$so_subTotal = "";
	$so_discTotal = "";

// LETS GET SO DETAILS
$get_sod = "SELECT * FROM `".$DBprefix."service_details` WHERE `sod_soid` = '$so_id'";  
$execute_get_sod = mysql_query($get_sod); 

while ($sod = mysql_fetch_array($execute_get_sod)){
	
	
	$sod_servprice = $sod["sod_servprice"];
	$sod_discount = $sod["sod_discount"];
	$sod_shipping = $sod["sod_shipping"];
	$sod_tax = $sod["sod_tax"];
	$sod_taxtotal = $sod["sod_taxtotal"];
	$sod_qty = $sod["sod_qty"];
	$sod_total = $sod["sod_total"];
	

	$item_subtotal = $sod_servprice * $sod_qty;
	$item_discount = ($sod_discount / 100) * $item_subtotal;
	
	$item_total = $item_subtotal - $item_discount;
	
	$so_shTotal = $so_shTotal + $sod_shipping;
	$so_subTotal = $so_subTotal + $item_total;

$so_discTotal = ($so_discount / 100) * $so_subTotal;
if ($so_tax == 1) { $so_taxTotal = $so_subTotal * 0.06; }

$so_total = $so_subTotal + $so_shTotal + $so_taxTotal - $so_discTotal;

} // END COUNT TOTALS
$allso_total = $allso_total + $so_total;
} // END GET ALL SO


?>

		<div id="content">
					<div id="powitanie">

<div class="status">
<div class="title">SERVICE ORDERS</div>
<div class="content">
<p>Open: <strong><? echo $soopen_count; ?></strong></p>
<p>Paid: <strong><? echo $sopaid_count; ?></strong></p>
<p>&nbsp;</p>
<p>Refunded: <strong><? echo $sorefunded_count; ?></strong></p>
<p>Canceled: <strong><? echo $socanceled_count; ?></strong></p>
<p>&nbsp;</p>
<p>TOTAL: <strong><? echo $sototal_count; ?></strong></p>
</div>
</div>
&nbsp;
<div class="status">
<div class="title">ACCOUNTING</div>
<div class="content">
<p>Paid Cash: <strong><? echo $sopaidcash_count; ?></strong></p>
<p>Paid Check: <strong><? echo $sopaidcheck_count; ?></strong></p>
<p>Paid PayPaL: <strong><? echo $sopaidpp_count; ?></strong></p>
<p>&nbsp;</p>
<p>Total Due: <strong><? echo "$" .number_format($allso_total, 2, '.', ','). ""; ?></strong></p>
</div>
</div>
&nbsp;
<div class="status">
<div class="title">CUSTOMERS</div>
<div class="content">
<p>Newest: <strong><? echo "<a href='in.php?show=mod&view=detail&modid=$cust_modid&cid=$cust_id'>$cust_lname $cust_fname</a>"; ?></strong></p>
<p>Total: <strong><? echo $customer_count; ?></strong></p>
</div>
</div>

<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>

</div>
</br>

